package cn.lyjuan.dwz_manage.core.java.service;


import cn.lyjuan.dwz_manage.core.base.pojo.ActionGroupPojo;
import cn.lyjuan.dwz_manage.core.java.dto.QueryResultBean;
import cn.lyjuan.dwz_manage.core.java.mapper.IMgActionGroupMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by ly on 2015/3/3.
 */
@Service("mgActionGroupService")
public class ActionGroupService
{
    @Autowired
    private IMgActionGroupMapper actionGroupMapper;

    /**
     * 后台搜索请求组信息
     * @param param
     * @param pn
     * @param ps
     * @return
     */
    public QueryResultBean<ActionGroupPojo> queryGroups(Map<String, String> param, int pn, int ps)
    {
        QueryResultBean<ActionGroupPojo> bean = new QueryResultBean<ActionGroupPojo>();

        List<ActionGroupPojo> list       = actionGroupMapper.selectGroups(param, (pn - 1) * ps, ps);
        int                   totalCount = actionGroupMapper.selectGroupCount(param);

        bean.setList(list);
        bean.setTotalCount(totalCount);

        return bean;
    }

    /**
     * 根据组编号查询组信息
     * @param groupid
     * @return
     */
    public ActionGroupPojo queryGroupById(int groupid)
    {
        return actionGroupMapper.selectById(groupid);
    }


    /**
     * 添加组信息
     * @param group
     */
    public void addGroup(ActionGroupPojo group)
    {
        group.setCreatetime(new Date());
        actionGroupMapper.insert(group);
    }

    /**
     * 更新组信息
     * @param group
     */
    public void updateActionGroup(ActionGroupPojo group)
    {
        actionGroupMapper.updateById(group);
    }

    /**
     * 锁定组信息
     * @param groupid
     */
    public void lockGroup(int groupid)
    {
        actionGroupMapper.lockGroupById(groupid);
    }

}
